package cn.itcast.service.impl;

import cn.itcast.mapper.ReportMapper;
import cn.itcast.pojo.*;
import cn.itcast.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private ReportMapper reportMapper;
    //根据员工性别统计人数
    @Override
    public List<EmpGender> empGenderData() {

        List<EmpGender> empGenders = reportMapper.empGenderData();

        return empGenders;
    }

    //根据员工职位统计人数
    @Override
    public EmpJobData empJobData() {

        List<EmpJobCount> empJobCounts = reportMapper.empJobCount();

        // 提取员工职位列表，将empJobCounts流中的每个元素映射为职位名称并收集为List
        List<String> jobList = empJobCounts.stream().map(maps -> maps.getJob()).toList();
        // 提取员工数量列表，将empJobCounts流中的每个元素映射为数量值并收集为List
        List<Integer> dataList = empJobCounts.stream().map(mapd -> mapd.getCount()).toList();
        // 创建员工职位数据对象，将职位列表和数量列表封装到EmpJobData实例中
        EmpJobData empJobData = new EmpJobData(jobList, dataList);

        return empJobData;
    }
    //统计学员学历信息
    @Override
    public List<StudentDegreeData> studentDegreeData() {
    List<StudentDegreeData> studentDegreeData1 = reportMapper.StudentDegreeData();

        return studentDegreeData1;
    }

    @Override
    public StudentCountData studentCountData() {
        List<StudentCount> studentCounts = reportMapper.StudentCountData();
        List<Integer> dataList = studentCounts.stream().map(maps -> maps.getCount()).toList();
        List<String> clazzlist = studentCounts.stream().map(mapc -> mapc.getName()).toList();

        StudentCountData studentCountData = new StudentCountData(clazzlist, dataList);
        return studentCountData;
    }


}
